package com.springboot.springautowired.javaDesignModel.proxyModel;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

/**
 * jdk实现动态代理的必要因素之一实现invocationhandler接口的类
 * 作用是通过反射的方式调用被代理对象的方法,并且在方法的调用前后加入别的业务逻辑操作
 */
public class InvocationHandlerClass implements InvocationHandler {
    private Object subject;

    public InvocationHandlerClass(Object subject) {
        this.subject = subject;
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        System.out.println("CallBefore");
        Object result = method.invoke(subject, args);
        System.out.println("CallAfter");
        return result;
    }
}
